package com.tledu.extends01;

public class OOP03 {
    public static void main(String[] args) {
        MiddleSchoolStudent middleSchoolStudent = new MiddleSchoolStudent();
        middleSchoolStudent.setName("张三");
//        middleSchoolStudent.askForLeave();
//        System.out.println(middleSchoolStudent.getName());
//        middleSchoolStudent.say();
//        System.out.println(middleSchoolStudent.sex);
//
//        middleSchoolStudent.askForLeave();

        logLeave(middleSchoolStudent);
        logLeave(new PrimarySchool());

        // 可以直接把子类转成父类的
        //  逻辑上，小学生也属于学生 （小范围可以自动转成大范围）
        Student student = new PrimarySchool();
        // 父类型中，拿不到子类型的属性的方法
        if (student instanceof PrimarySchool) {
            PrimarySchool primarySchool = (PrimarySchool) student;
            primarySchool.youngPioneers = "少先队员";
            System.out.println(primarySchool.youngPioneers);
//        System.out.println(student);
        }
    }

    /**
     * 记录请假日志
     * 每次一旦出现请假，就通过这个方法，记录一个日志
     * 参数 学生，只要是学生类型的都可以
     */
    public static void logLeave(Student student) {
        student.askForLeave();
        System.out.println("记录学生请假");
    }
}
